package com.dotflat.fin.service.impl;

import com.dotflat.fin.cnst.Const;
import com.dotflat.fin.domain.SystemWalletFlow;
import com.dotflat.fin.repository.SystemWalletFlowRepository;
import com.dotflat.fin.service.SystemWalletFlowService;
import com.matt.domain.Clientele;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class SystemWalletFlowServiceImpl implements SystemWalletFlowService {

    @Autowired
    private SystemWalletFlowRepository systemWalletFlowRepository;

    private SystemWalletFlow generateFlowObject(Clientele creator, String title, Date date){
        SystemWalletFlow cmsWalletFlow = new SystemWalletFlow();

        cmsWalletFlow.setCreatedBy(creator.getStaffId());
        cmsWalletFlow.setClienteleId(creator.getId());
        cmsWalletFlow.setAreaId(creator.getAreaId());

        cmsWalletFlow.setCompanyName(creator.getName());
        cmsWalletFlow.setAccountName(creator.getMobile());

        cmsWalletFlow.setBusinessName(title);
        cmsWalletFlow.setBusinessTime(date);

        return cmsWalletFlow;
    }

    public SystemWalletFlow generateIncomeFlow(Clientele creator, String title, Date date, Const.FLOW_SOURCE_TYPE flowSourceType, Long amount){
        SystemWalletFlow cmsWalletFlow = generateFlowObject(creator, title, date);

//        cmsWalletFlow.setAreaId(creator.getAreaId());
//        cmsWalletFlow.setBillType(payStepType.codeOf());

        cmsWalletFlow.setTotalMoney(amount);
        cmsWalletFlow.setIncomeMoney(amount);

        cmsWalletFlow.setType(Const.FLOW_TYPE.INCOME.codeOf());
        cmsWalletFlow.setSourceType(flowSourceType.codeOf());

        systemWalletFlowRepository.save(cmsWalletFlow);

        return cmsWalletFlow;
    }

//    public CmsWalletFlow generateExpensesFlow(ShopUser creator, String title, Date date, Const.FLOW_SOURCE_TYPE flowSourceType,  Long amount){
//        CmsWalletFlow cmsWalletFlow = generateFlowObject(creator, title, date);
//
//        cmsWalletFlow.setTotalMoney(amount);
//        cmsWalletFlow.setPayMoney(amount);
//
//        cmsWalletFlow.setType(Const.FLOW_TYPE.EXPENSES.codeOf());
//        cmsWalletFlow.setSourceType(flowSourceType.codeOf());
//
//        insert(cmsWalletFlow);
//
//        return cmsWalletFlow;
//    }
//
//    public CmsWalletFlow generateCommisionFlow(ShopUser creator, String title, Date date, Const.FLOW_SOURCE_TYPE flowSourceType, Long amount, Long commision, Integer rate){
//        CmsWalletFlow cmsWalletFlow = generateFlowObject(creator, title, date);
//
//        cmsWalletFlow.setTotalMoney(amount);
//        cmsWalletFlow.setCommissionMoney(commision);
//        cmsWalletFlow.setRate(rate);
//
//        cmsWalletFlow.setType(Const.FLOW_TYPE.COMMISION.codeOf());
//        cmsWalletFlow.setSourceType(flowSourceType.codeOf());
//
//        insert(cmsWalletFlow);
//        return cmsWalletFlow;
//    }
//
//    public Map<String,Integer> statisticsAmount(){
//        HashMap<String, Integer> map = new HashMap<>();
//
//        Integer custodyAmount = cmsWalletFlowRepository.statisticsCustodyAmount();
//        Integer projectAmount = cmsWalletFlowRepository.statisticsProjectAmount();
//        Integer payAmount = cmsWalletFlowRepository.statisticsPayAmount();
//        Integer incomeAmount = cmsWalletFlowRepository.statisticsIncomeAmount();
//        int custodyMoney=0;
//        int projectMoney=0;
//        int payMoney=0;
//        int incomeMoney=0;
//        if(custodyAmount !=null){
//            custodyMoney=custodyAmount;
//        }
//        if(projectAmount !=null){
//            projectMoney=projectAmount;
//        }
//        if(payAmount !=null){
//            payMoney=payAmount;
//        }
//        if(incomeAmount !=null){
//            incomeMoney=incomeAmount;
//        }
//        map.put("custodyMoney",custodyMoney);
//        map.put("projectMoney",projectMoney);
//        map.put("payMoney",payMoney);
//        map.put("incomeMoney",incomeMoney);
//        return map;
//    }

}
